< previous page page_11 next page >

Page 11
and ScaleHeight properties. Because you must specify the form's height and width in twips, you should calculate these values in twips.
Then when you resize the form, add these amounts to the desired width and height to allow room for the borders and title bar. The following Visual Basic code shows how to size a form so that its interior drawing area is 1 logical inch square.
e10a6a0a59f035e870d90cca05b85fce.gif
Dim extra_wid As Single
Dim extra_hgt As Single

    extra_wid = Width  ScaleWidth
    extra_hgt = Height  ScaleHeight
    Me.Width = 1440 + extra_wid
    Me.Height = 1440 + extra_hg
Example program Insize demonstrates this code. When it starts, the program creates two forms. It sets the Width and Height of the first to 1 inch. It uses code similar to the previous code to set the interior width and height of the second form to 1 inch. The program draws a grid in both forms, so you can see that the drawing area in the first is not square.
When you use this method, you must be sure that you use the correct units of measurement. A form's Width and Height are always specified in twips. Its ScaleWidth and ScaleHeight may be defined in some other units, including a custom coordinate system. In that case, you must convert the ScaleWidth and ScaleHeight into twips as shown in the following code.
e10a6a0a59f035e870d90cca05b85fce.gif
extra_wid = Width  ScaleX(ScaleWidth, ScaleMode, vbTwips) 
extra_hgt = Height  ScaleY(ScaleHeight, ScaleMode, vbTwips)
This fails if the resizing causes the form to rearrange its menus. If the form is wide, it may be able to display all of its menus in one row within its title bar. If you make the form too narrow, it may need to display the title bar on multiple rows. In that case, the title bar height increases and the amount allowed by the program will not be enough to hold the larger title bar.
You must also allow room for borders on picture boxes that have them. Suppose you want to create a picture box with an interior area 1500 twips tall and 2500 twips wide. Suppose the form that contains the picture box has defined a custom scale. To correctly size the picture box, you must convert its size into the form's custom coordinate system, allowing room for its border.
Example program BoxSize, shown in Figure 1.5, uses the following code to display two picture boxes. The first includes extra room for its borders while the second does not. The program draws a diamond shape in each picture box, so you can see that the second picture box is not big enough to hold its desired drawing area.
e10a6a0a59f035e870d90cca05b85fce.gif
' Size the picture boxes and draw a diamond in each.
Private Sub Form_Load()
Dim wid As Single
Dim hgt As Single

 
< previous page page_11 next page >